package inno;

import pkg.inno.fileshare.R;

import java.util.concurrent.ExecutionException;

import model.MenuSubItem;
import Tasks.GetMenuItemAsync;
import activities.MenuItemView;
import activities.ProductsView;
import adapters.ExpandableListAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

public class FileShareActivity extends Activity implements OnChildClickListener {

	ExpandableListView _expandableListView;
	Button _buttonObject;
	ExpandableListAdapter adapter;
	
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        _expandableListView=(ExpandableListView)findViewById(R.id.expandableMenus);
        try {
			 adapter=new GetMenuItemAsync().execute(this).get();
			_expandableListView.setAdapter(adapter);
			_expandableListView.setOnChildClickListener(this);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

	public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) 
	{
		//ExpandableListAdapter adapter=(ExpandableListAdapter) parent.getAdapter();
		//MenuItem group=(MenuItem) adapter.getGroup(groupPosition);
		//MenuSubItem objx=group.get_childList().get(childPosition);
		MenuSubItem objx2=(MenuSubItem) adapter.getChild(groupPosition, childPosition);

		if (objx2.get_parentMenuId()==25) 
		{
			Intent intentObj = new Intent(FileShareActivity.this, ProductsView.class );
			
			startActivity(intentObj);
			
			finish();
		}
		//Log.i("onChildClick",objx2.get_menuName()+" "+objx.get_menuName());
		else 
		{
			Intent intentObj = new Intent(FileShareActivity.this, MenuItemView.class );
			
			Bundle bundleObj=new Bundle();
			bundleObj.putString("subMenuName", objx2.get_menuName());
			bundleObj.putString("subMenuId", String.valueOf(objx2.get_parentMenuId()));
			
			intentObj.putExtra("menuBundles",bundleObj);
			
			startActivity(intentObj);
			
			finish();
		}

		return true;
	}
    
}